package com.aash.persistence.generic;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class JpaTransactionAspect {

	@Around("execution(* com.aash.persistence.dao.*.*(..))")
	public Object handleTransactin(ProceedingJoinPoint pjp) throws Throwable {
		((GenericDaoJpaImpl<?, ?>)pjp.getTarget()).createEm();
		try {
			Object retVal = pjp.proceed();
			return retVal;
		} finally {
			((GenericDaoJpaImpl<?, ?>)pjp.getTarget()).closeEm();
		}
	}
}
